package icedot.app.android.nativeso;

import android.os.Message;
import android.util.Log;

public class NativeClient 
{
	static 
	{
		System.loadLibrary("nativeclient");
	}

	public static final int s_noNetwork = 2;
	public static final int s_httpSuccess = 6;
	public static final int s_httpProcess = 7;
	public static final int s_httpError = 8;
	
	public native byte[] test();
	public native void init(String ip,int port,String logPath,int level);		//初始化
	public native void httpPost(String url,String jsonStr,String flag); //接口调用
	public native void httpGet(String url,String jsonStr,String flag);
	public native void httpGetFile(String url,String fileName,String flag,boolean process);
	public native void httpUploadFile(String url,String jsonStr,String flag,boolean process);
	public native void close(); //关闭	
	
	private NativeHandler 	_handler = null;
	private boolean 		_isconnect = false;    //与服务器是否建立了连接
	private NetworkNotify 	_notify = null;
	
	public void setNetworkNotify(NetworkNotify notify)
	{
	    _notify = notify;
	}
	
	public NetworkNotify getNetworkNotify()
	{
	    return _notify;
	}
	
	public void setHandler(NativeHandler handler)
	{
		_handler = handler;
	}
	
	public void setConnect(boolean connect)
	{
		_isconnect = connect;
	}
	
	public boolean getConnect()
	{
		return _isconnect;
	}
	
	public void onNativeRecive(String flag,int type,byte[] data)
	{
		if(_handler == null)
		{
			Log.d("onNativeRecive", "_handler is null");
			return;
		}
		Http_result obj = new Http_result();
		obj._flag = flag;
		obj._data = data;
		Message msg = Message.obtain();
		msg.obj = obj;
		msg.arg1 = type;
		_handler.sendMessage(msg);
	}
}
